<div class="bjui-pageContent" style="width: 100%;">
	<table class="table table-bordered" id="datagrid-tree" data-toggle="datagrid" data-options="{
	        height: '100%',
	        width: '100%',
	    	tableWidth:'98%',
	        gridTitle : '权限列表',
	        showToolbar: true,
	        toolbarItem: 'add,del,|,save,cancel',
	        local: 'local',
	        dataUrl: '{{url('admin/role')}}',
	        inlineEditMult: false,
	        postData:{_token:'{{csrf_token()}}'},
        	editUrl: '{{url("admin/role/edit")}}?_token={{csrf_token()}}',
	        paging: false,
	        columnMenu: false,
	        isTree: 'name',
	        fieldSortable:false,
	        afterSave:function(){
	        	$('#datagrid-tree').datagrid('refresh');
	        },
        	delUrl:'{{url("admin/role/roleDel")}}',
        	delType:'GET',
		    treeOptions: {
		        expandAll: false,
		        add: true,
		        simpleData: true,
		        keys: {
		            parentKey: 'a_id',
		            order: 'orders',
		            isExpand  : 'isExpand'
		        }
		    },
		    dropOptions: {
		        drop: true,
		        position: 'before',
		        dropUrl: '{{url("admin/role/edit")}}?_token={{csrf_token()}}',
		        beforeDrag: datagrid_tree_beforeDrag,
		        beforeDrop: datagrid_tree_beforeDrop,
		        afterDrop: 'array'
		    }
	   }">
		<thead>
			<tr>
		        <th data-options="{name:'name', align:'center', width:300, rule:'required'}">角色名称</th>
	            <th data-options="{name:'role', align:'center', width:200}">权限名称</th>
	            <th data-options="{name:'showed', align:'center',type:'boolean',quickfilter:false,render:function(value){return value ? '√' : '×'}}">是否做为菜单</th>
	            <th data-options="{name:'a_id', align:'center',type:'select',items:cate_data,align:'left'}">上级</th>
	            <th data-options="{align:'center',render:datagrid_operation}">操作列</th>
		    </tr>
		        
		</thead>
	</table>
</div>

<script type="text/javascript">
	function datagrid_operation() {
	    var html = '<button type="button" class="btn-green" data-toggle="edit.datagrid.tr">编辑</button>'
	        + '<button type="button" class="btn-red" data-toggle="del.datagrid.tr">删除</button>'
	    return html
	}
	
	//不能拖动一级父节点
	function datagrid_tree_beforeDrag(tr, data) {
	    if (data && data.level == 0) {
	        return false
	    }
	    return true
	}
	// 不能将子节点拖为一级父节点
	function datagrid_tree_beforeDrop(data, targetData, position) {
		/*if (targetData && targetData.level == 0 && position !== 'append') {
	        return false
	   }*/
	    return true
	}
	
	function cate_data(){
		var data='[{"0":"=顶级="},';
		@foreach($auths as $v)
			data+='{'+'"{{$v->id}}":"{{$v->_cate_name}}"'+'},';
		@endforeach
		data+=']';
		return data;
	}
</script>